import type { ApiFn, FormList, SearchList } from "@/types/form";
import type { TableColumn, TableOptions } from "@/types/public";
import { FORM_REQUIRED } from "@/utils/config";
import { getDemo } from "@/api/demo.ts";

// 搜索数据
export const searchList = (): SearchList[] => [
    {
        label: "货物名称",
        name: "username",
        component: "ApiSelect",
        wrapperWidth: 400,
        componentProps: {
            api: getDemo as ApiFn,
            apiResultKey: "projects",
            params: {
                isAll: true,
            },
            fieldNames: {
                label: "label",
                value: "value",
            },
        },
    },
];

/**
 * 表格数据
 * @param optionRender - 渲染操作函数
 */
export const tableColumns = (optionRender: TableOptions<object>): TableColumn[] => {
    return [
        {
            title: "ID",
            dataIndex: "id",
            width: 100,
        },
        {
            title: "货物名称",
            dataIndex: "username",
            width: 400,
        },
        {
            title: "添加日期",
            dataIndex: "content",
            width: 150,
        },
        {
            title: "操作",
            dataIndex: "operate",
            width: 200,
            render: (value: unknown, record: object) => optionRender(value, record),
        },
    ];
};

// 新增数据
export const createList = (): FormList[] => [
    {
        label: "货物名称",
        name: "username",
        rules: FORM_REQUIRED,
        component: "ApiSelect",
        componentProps: {
            api: getDemo as ApiFn,
            apiResultKey: "projects",
            params: {
                isAll: true,
            },
            fieldNames: {
                label: "label",
                value: "value",
            },
        },
    },
];
